/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Jdbcutil;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 *
 * @author Thanh Minh
 */
public final class MysqldataAccesshelper {
     private Statement sm;    
    
    public MysqldataAccesshelper() throws SQLException{
        open();
    }
    public void open() throws SQLException{
        Connection connection =MySQLConnectionUtil.getInstance().getConnection();
        this.sm=connection.createStatement();
    }
    public void close() throws SQLException{
       try{
           this.sm.close();
       }
       catch(SQLException ex){
           System.out.println(ex.getMessage());
       }
    }
     public ResultSet executeQuery(String sql) {
      ResultSet rs = null;
      try {
         rs = this.sm.executeQuery(sql);
      } catch (SQLException ex) {
         System.out.println(ex.getMessage());
      }
      return rs;
   }
      public int executeUpdate(String sql) {
      int num = -1;
      try {
         num = this.sm.executeUpdate(sql);
      } catch (SQLException ex) {
        System.out.println(ex.getMessage());
      }
      return num;
   }
}
